package org.jeecg.modules.zhongche.plc.controller;


import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.jeecg.modules.zhongche.plc.api.PlcDataType;
import org.jeecg.modules.zhongche.plc.model.PLCWriteDTO;
import org.jeecg.modules.zhongche.plc.service.PlcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("/zhongche/plc")
@Tag(name = "PLCController", description = "plc控制")
public class PLCController {


    @Autowired
    private PlcService plcService;

    @Operation(summary = "发送机器人编")
    @GetMapping("/sendDb")
    public Object sendDb(Integer db, String value) {
        plcService.write(db, "150", PlcDataType.WORD, db);
        return "发送机器人编号成功";
    }

    @GetMapping("/writeClass")
    public Object writeClass(Integer db) {

        PLCWriteDTO writeDTO = new PLCWriteDTO();
        writeDTO.setDbNum(db);
        writeDTO.setDb150(db);
        boolean b = plcService.writeClass(writeDTO);
        return "发送机器人编号成功";
    }


    @GetMapping("/sendLine")
    public Object sendLine(@NotEmpty(message = "db编号不能为空") Integer db, @NotEmpty(message = "焊缝不能为空") String value) {
        plcService.write(db, "154", PlcDataType.WORD, value);
        return "发送焊缝成功";
    }

    @GetMapping("/sendParameter")
    public Object sendParameter(Integer db, String value) {
        plcService.write(db, "190.0", PlcDataType.BOOL, 1);
        return "发送参数确认成功";
    }

    @GetMapping("/sendStart")
    public Object sendStart(Integer db, String value) {
        plcService.write(db, "190.1", PlcDataType.BOOL, 1);
        return "发送开始任务成功";
    }


    @GetMapping("/sendOilPumpX")
    public Object sendOilPumpX(Integer db, String value) {
        plcService.write(db, "190.3", PlcDataType.BOOL, 1);
        return "发送x油泵成功";
    }

    @GetMapping("/sendOilPumpYZ")
    public Object sendOilPumpYZ(Integer db, String value) {
        plcService.write(db, "190.4", PlcDataType.BOOL, 1);
        return "发送yz油泵打油成功";
    }
}
